from widgets.scriptWidgets.ScriptWidget import ScriptWidget
from enums.WidgetType import WidgetType
from PySide6.QtWidgets import QLabel
from ..ScriptInput import ScriptInput


class InputText(ScriptWidget):
    def __init__(self, initType=None):
        super().__init__(WidgetType.INPUT_TEXT)

        self.pressTime = 0
        self.initType = initType

        self.labTitle = QLabel('输入:', self)
        self.labTitle.setFixedSize(30, self.lineHeight)
        self.addWidget(self.labTitle)

        self.newLineSpaceWidth = self.labTitle.width() + self.intervalX

        self.inputText = ScriptInput(self, '文字', 16, 'string')
        self.addWidget(self.inputText)

        if initType == 'edit' or initType == 'create':
            self.addOperate()

    @property
    def data(self):
        return {
            "type": self.type.value,
            'text': self.inputText.text,
            'enable': self.switchEnable.isChecked()
        }

    @data.setter
    def data(self, data):
        self.setData(data)
        self.inputText.text = data['text']
